package com.example.roadeyeserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.roadeyeserver.entity.HolidayInfo;
import com.example.roadeyeserver.entity.request.HolidayRequest;
import com.example.roadeyeserver.mapper.HolidayInfoMapper;
import com.example.roadeyeserver.service.HolidayInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class HolidayInfoServiceImpl extends ServiceImpl<HolidayInfoMapper, HolidayInfo> implements HolidayInfoService {
    @Override
    public List<String> getHolidayByYearAndType(HolidayRequest request) {
        // 年份不能为空
        Integer year = request.getYear();
        if (year == null) {
            return null;
        }
        List<HolidayInfo> holidayInfos = this.list(new LambdaQueryWrapper<HolidayInfo>()
                .eq(HolidayInfo::getYear, year)
                .eq(request.getType() != null, HolidayInfo::getType, request.getType())
                // 按日期升序排列
                .orderByAsc(HolidayInfo::getDate)
        );
        return holidayInfos.stream().map(HolidayInfo::getDate).collect(Collectors.toList());
    }
}
